package com.qf.user.controller;

import com.qf.core.vo.R;
import com.qf.user.entity.Menu;
import com.qf.user.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 菜单管理 前端控制器
 * </p>
 *
 * @author yxh
 * @since 2023-10-29
 */
@RestController
@RequestMapping("/menu")
@CrossOrigin
public class MenuController {
    @Autowired
    private MenuService menuService;

    /**
     * 菜单列表
     * @return
     */
    @PostMapping("menus")
    public R menus(){
        return R.ok(menuService.selectAllMenus());
    }
    @PostMapping("update")
    public R update(@RequestBody Menu menu){
        boolean b = menuService.updateById(menu);
        if (!b){
            return R.fail();
        }
        return R.ok();
    }

    @PostMapping("delete")
    public R delete(@RequestBody Menu menu){
        boolean b = menuService.removeById(menu.getId());
        if (!b) {
            return R.fail();
        }
        return R.ok();
    }

    @PostMapping("add")
    public R add(@RequestBody Menu menu){
        return R.ok(menuService.add(menu));
    }

    @GetMapping("all")
    public R all(){
        return menuService.selectMenus();
    }



}
